package com.briup.corejava.day16;

/**
 * 守护线程的案例
 */
public class Test2 {
    public static void main(String[] args) {
        Thread t1 = new Thread(){
            @Override
            public void run(){
                for (int i = 1; i <= 30; i++) {
                    System.out.println("..."+i);
                    try {
                        Thread.sleep(100);
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                }
            }
        };
        Thread t2 = new Thread(new Runnable() {
            @Override
            public void run() {
                for (int i = 100; i >= 50; i--) {
                    System.out.println(i+"...");
                    try {
                        Thread.sleep(100);
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                }
            }
        });
        // 设置t2为守护线程
        // t2.setDaemon(true); // jvm关闭不关心t2是否执行完毕
        // 设置优先级
        t1.setPriority(1);
        t2.setPriority(10);

        t1.start();
        t2.start();
    }
}
